﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xant.FlowEngine.Interface;

namespace Xant.FlowEngine.Core
{
    public class ProcessInstance : AbstractProcess
    {
        #region 变量
        protected Status currentStatus = Status.None;

        public delegate void StatusChangingHandler(ProcessInstance process, Status newStatus, ref bool cancel);
        public StatusChangingHandler StatusChanging;
        public delegate void StatusChangedHandler(ProcessInstance process);
        public StatusChangedHandler StatusChanged;

        #endregion

        #region 属性

        /// <summary>
        /// 流程模板主键
        /// </summary>
        public Guid TemplateId { get; set; }

        /// <summary>
        /// 归属流程主键
        /// </summary>
        public Guid? OwnerProcessId { get; set; }

        /// <summary>
        /// 归属流程实例
        /// </summary>
        public ProcessInstance OwnerProcess { get; set; }

        /// <summary>
        /// 流程状态
        /// </summary>
        public Status Status
        {
            get { return currentStatus; }
            internal set
            {
                if (StatusChanging != null)
                {
                    bool cancel = false;
                    StatusChanging(this, value, ref cancel);
                    if (cancel)
                    {
                        return;
                    }
                }
                currentStatus = value;
                if (StatusChanged != null)
                {
                    StatusChanged(this);
                }
            }
        }

        public DateTime? StartTime { get; internal set; }

        public DateTime? EndTime { get; internal set; }

        /// <summary>
        /// 流程发起人
        /// <remarks>默认为流程创建者，但与创建者信息不同的是，发起人信息中包含所属部门；另外考虑使用此属性解决员工离职后流程交接的问题</remarks>
        /// </summary>
        public IStaffMember Initiator { get; set; }

        #endregion

        #region 构造函数
        #endregion

    }
}
